from flask import Blueprint, request

user_router = Blueprint('users', __name__, url_prefix="/user")


user_list = [[1, '小明', 20]]


@user_router.route('/add', methods=['post'])
def add_user():
    data = request.form
    id = int(data.get('id'))
    name = data.get('name')
    age = data.get('age')
    for i in user_list:
        id_u = i[0]
        name_u = i[1]
        age_u = i[2]
        if id_u == id or name_u == name:
            return '已存在id或name'
    else:
        user_list.append([id, name, age])
        return user_list


@user_router.route('/delete/<int:id>', methods=['delete'])
def delete_user(id):
    data = request.form
    id_user = int(data.get('id'))
    for index, i in enumerate(user_list):
        id_u = i[0]
        if id_u == id:
            user_list.pop(index)
            return user_list
        else:
            return '没找到该用户'


@user_router.route('/select/<int:id>')
def select_user(id):
    for i in user_list:
        id_u = i[0]
        if id_u == id:
            return [i[0], i[1], i[2]]
    else:
        return '找不到'






